﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;

namespace Omu.AwesomeDemo.WebUI.Areas.Veggies.Controllers
{
    public class HomeController : Controller
    {
        private IRepo<Fruit> fruitRepo;

        public HomeController(IRepo<Fruit> fruitRepo)
        {
            this.fruitRepo = fruitRepo;
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult CreateFruit()
        {
            return View();
        }

        [HttpPost]
        public ActionResult CreateFruit(FruitInput input)
        {
            if (!ModelState.IsValid) return View(input);
            fruitRepo.Insert(new Fruit {Name = input.Name});
            return Content("ok");
        }
    }

    public class FruitInput
    {
        [Required]
        public string Name { get; set; }
    }
}
